{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Build Array from Permutation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: buildArray"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #基于排列构建数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个 <strong>从 0 开始的排列</strong> <code>nums</code>（<strong>下标也从 0 开始</strong>）。请你构建一个 <strong>同样长度</strong> 的数组 <code>ans</code> ，其中，对于每个 <code>i</code>（<code>0 &lt;= i &lt; nums.length</code>），都满足 <code>ans[i] = nums[nums[i]]</code> 。返回构建好的数组 <code>ans</code> 。</p>\n",
    "\n",
    "<p><strong>从 0 开始的排列</strong> <code>nums</code> 是一个由 <code>0</code> 到 <code>nums.length - 1</code>（<code>0</code> 和 <code>nums.length - 1</code> 也包含在内）的不同整数组成的数组。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [0,2,1,5,3,4]\n",
    "<strong>输出：</strong>[0,1,2,4,5,3]<strong>\n",
    "解释：</strong>数组 ans 构建如下：\n",
    "ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n",
    "    = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]\n",
    "    = [0,1,2,4,5,3]</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [5,0,1,2,3,4]\n",
    "<strong>输出：</strong>[4,5,0,1,2,3]\n",
    "<strong>解释：</strong>数组 ans 构建如下：\n",
    "ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n",
    "    = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]\n",
    "    = [4,5,0,1,2,3]</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 1000</code></li>\n",
    "\t<li><code>0 &lt;= nums[i] &lt; nums.length</code></li>\n",
    "\t<li><code>nums</code> 中的元素 <strong>互不相同</strong></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [build-array-from-permutation](https://leetcode.cn/problems/build-array-from-permutation/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [build-array-from-permutation](https://leetcode.cn/problems/build-array-from-permutation/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[0,2,1,5,3,4]', '[5,0,1,2,3,4]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ret=[0]*len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            ret[i]=nums[nums[i]]\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "         ans=[0]*len(nums)\n",
    "         for i in range(len(nums)):\n",
    "            ans[i]=nums[nums[i]]\n",
    "         return ans\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = [None] * len(nums)\n",
    "        for i, num in enumerate(nums):\n",
    "            ans[i] = nums[num]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        ans = [0] * n\n",
    "        for i in range(n):\n",
    "            ans[i] = nums[nums[i]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        res=[]\n",
    "        for i in range(len(nums)):\n",
    "            res.append(nums[nums[i]])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        anw =[]\n",
    "        for i in range(len(nums)):\n",
    "            anw.append(nums[nums[i]])\n",
    "        return anw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        list2=[0]*len(nums)\n",
    "        for i,num  in enumerate(nums):\n",
    "            list2[i]=nums[num]\n",
    "        return list2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i,x in enumerate(nums):\n",
    "            ans.append(nums[x])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        res = [0]*n\n",
    "        for i in range(n):\n",
    "            res[i] = nums[nums[i]]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        l=len(nums)\n",
    "        ans=[0]*l\n",
    "        for i in range(l):\n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n=len(nums)\n",
    "        res=[0]*n\n",
    "        for i in range(n):\n",
    "            res[i]=nums[nums[i]]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = [0]*len(nums)\n",
    "        for i in range(len(ans)):\n",
    "            ans[i] = nums[nums[i]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "       return [nums[nums[i]] for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        res=[]\n",
    "        for i in range(len(nums)):\n",
    "            res.append(nums[nums[i]])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        ans = [0] * n\n",
    "        for i in range(n):\n",
    "            k = nums[i]\n",
    "            ans[i] = nums[k]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        res = [0]*len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            res[i] = nums[nums[i]]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[0]*len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]] for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]] for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        k=len(nums)\n",
    "        for i in range(0,k):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        length=len(nums)\n",
    "        ans=[0]*length\n",
    "        for i in range(length):\n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]] for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[i] for i in nums]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]] for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(0)\n",
    "        for i in range(len(nums)):\n",
    "            \n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        result = [0] * n\n",
    "        for i in range(n):\n",
    "            result[i] = nums[nums[i]]\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        index = 0\n",
    "        while index < len(nums):\n",
    "            ans.append(nums[nums[index]])\n",
    "            index += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        return [nums[nums[_]] for _ in range(n)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        a = 0\n",
    "        for i in range(len(nums)):\n",
    "            a = nums[nums[i]]\n",
    "            ans.append(a)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]] for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ret=[]\n",
    "        for i in range(0,len(nums)):\n",
    "            ret.insert(i,nums[nums[i]])\n",
    "            \n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        anT = list()\n",
    "        num = 0\n",
    "        for i in nums:\n",
    "            anT.append(nums[i])\n",
    "            num = num+1\n",
    "        return anT\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = [0] * len(nums)\n",
    "        for i in range(0, len(nums)):\n",
    "            temp = nums[i]\n",
    "            ans[i] = nums[temp]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        # 第一次遍历编码最终值\n",
    "        for i in range(n):\n",
    "            nums[i] += 1000 * (nums[nums[i]] % 1000) \n",
    "        # 第二次遍历修改为最终值\n",
    "        for i in range(n):\n",
    "            nums[i] //= 1000\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        return [nums[nums[_]] for _ in range(n)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.insert(i, nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]]   for i in range(len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        length=len(nums)\n",
    "        ans=[0]*length\n",
    "        for i in range(length):\n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "    \treturn [nums[nums[i]] for i in range(0,len(nums))]\n",
    "    \t\n",
    "        \n",
    "    \t\n",
    "    \t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = [0] * len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            ans[i] = nums[nums[i]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        r =[]\n",
    "        for i in range(len(nums)):\n",
    "            r.append(nums[nums[i]])\n",
    "\n",
    "        return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[0]*len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        \n",
    "        a=[]\n",
    "        for i in range(len(nums)):\n",
    "            \n",
    "            a.append(nums[nums[i]])\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        # 第一次遍历编码最终值\n",
    "        for i in range(n):\n",
    "            nums[i] += 1000 * (nums[nums[i]] % 1000)\n",
    "        # 第二次遍历修改为最终值\n",
    "        for i in range(n):\n",
    "            nums[i] //= 1000\n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums:        List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans\n",
    "      \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ret = []\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            ret.append(nums[nums[i]])\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(len(nums)):\n",
    "            ans.insert(i, nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        # ans = []\n",
    "        # for i in range(len(nums)):\n",
    "        #     ans.append(nums[nums[i]])\n",
    "        # return ans\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums[i] += 1000 * (nums[nums[i]] % 1000)\n",
    "        for i in range(n):\n",
    "            nums[i] //= 1000\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[0]*len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            ans[i]=nums[nums[i]]\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        return [nums[nums[_]] for _ in range(n)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        return [nums[nums[_]] for _ in range(n)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        l=len(nums)\n",
    "        ans=[]\n",
    "        for i in range(0,l):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        a=len(nums)\n",
    "        for i in range(0,a):\n",
    "            ans.append(nums[nums[i]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[nums[i]] for i in range(0, len(nums))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def buildArray(self, nums: List[int]) -> List[int]:\n",
    "        ans = len(nums)*[0]\n",
    "        for i in range(len(nums)):\n",
    "            ans[i] = nums[nums[i]]\n",
    "        return ans"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
